package com.example.administrator.managesystem.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.managesystem.R;
import com.example.administrator.managesystem.bean.CameraListBean;
import com.example.administrator.managesystem.bean.GetCameraBean;

import java.util.ArrayList;
import java.util.List;

public class GridCameraAdapter extends BaseAdapter {
    private List<String> series_list=new ArrayList<>();
    private Context mContext;


    public GridCameraAdapter(Context mContext) {
        this.mContext = mContext;
        // this.names=names;
    }
    public void addDatas(List<CameraListBean.DataBean> myList){
        series_list.clear();
        for(int i=0;i<myList.size();i++){
            series_list.add(myList.get(i).getDevice_number());
        }

    }


    @Override
    public int getCount() {
        return series_list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return series_list.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }


    @SuppressLint("ResourceType")
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {


        ViewHolder viewHolder;
        if(convertView==null) {
            convertView=View.inflate(mContext, R.layout.camera_grid_item, null);
            viewHolder=new ViewHolder();
            viewHolder.camera_name=convertView.findViewById(R.id.camera_name);
            viewHolder.deleteView = convertView.findViewById(R.id.delete_markView);

            convertView.setTag(viewHolder);//store up viewHolder
        }else {

            viewHolder=(ViewHolder)convertView.getTag();
        }


        viewHolder.camera_name.setText( series_list.get(position));

        return convertView;
    }

    private class ViewHolder{
        TextView camera_name;
        ImageView deleteView;

    }

}